package cn.com.gridinfo.sooc.core.my.setting;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.widget.ProgressBar;
import android.widget.TextView;

import cn.com.gridinfo.sooc.common.UrlConst;
import cn.com.gridinfo.sooc.core.my.setting.activity.SettingActivity;
import cn.com.gridinfo.sooc.utils.HttpUrl;

/**
 * 更新  未完成
 * Created by 刘晓晨 on 2015/12/15.
 */
public class Update {
    private SettingActivity activity;
    public int code = 0;
    public String version = "";
    private String message;
    private String strURL;
    private String must="";
    private String fileEx = "";
    private String fileNa = "";
    private String currentFilePath = "";
    private String currentTempFilePath = "";
    private ProgressDialog dialog;
    private static final String TAG = "AutoUpdate";
    NotificationManager nm;
    static final int NOTIFICATION_ID = 0x123;
    //下载地址
    String download_url = null;
    //更新信息
    String update_info = null;
    //更新需要的 md5校验
    String md5 = null;
    public Update(SettingActivity settingActivity,NotificationManager notificationManager){
        this.activity=settingActivity;
        this.nm=notificationManager;
    }
    public void check(){
        if(isNetworkAvailable(this.activity)==false){
            return;
        }else {
            checkEdit();
        }
    }
    /**
     * 检查网络是否可用
     * @param ctx
     * @return
     */
    public static boolean isNetworkAvailable(Context ctx) {
        try {
            ConnectivityManager cm = (ConnectivityManager) ctx
                    .getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo info = cm.getActiveNetworkInfo();
            return (info != null && info.isConnected());
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
    /**
     * 得到版本信息
     */
    public void getCurrentVersion() {
        try {
            PackageInfo info = activity.getPackageManager().getPackageInfo(
                    activity.getApplication().getPackageName(), 0);
            code = info.versionCode;
            version = info.versionName;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
    }
    /**
     * 请求服务器，看是否有需要更新的版本
     */
    ProgressBar pb;
    TextView text;
    Notification notify;
    public void checkEdit(){
//        String url= HttpUrl.getHttpUrl(UrlConst.Module.appVersion.toString()
//        ,"getUpdateInfo",false);

    }
}
